package cn.redragon.soa.common.web;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import java.io.IOException;
import org.apache.commons.lang3.StringUtils;

public class JacksonXssDeserializer extends StdDeserializer<String> {

    private static final long serialVersionUID = 6517465663078103528L;

    public JacksonXssDeserializer() {
        super(String.class);
    }

    @Override
    public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        String value = p.getValueAsString();
        return StringUtils.isBlank(value) ? value : JsoupUtil.clean(value);
    }
}
